﻿Imports System.Data.OleDb

Public Class Addphoto
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Submit.Click
        Dim myGUID = Guid.NewGuid()
        Dim newFileName As String = myGUID.ToString() & ".jpg"
        Dim fileLocationOnServerHardDisk = Request.MapPath("Pictures") & "/" & newFileName
        fup_Picture.SaveAs(fileLocationOnServerHardDisk)
        'meaning: upload a new image named by the system.'
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("KOPConn").ConnectionString)
        Dim SqlString As String = "Insert into Photolist(PhotoName,UploadDate,Author,Category,Location,Picture) Values (@f1,@f2,@f3,@f4,@f5,@f6)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        oleDbConn.Open()
        cmd.Parameters.AddWithValue("@f1", tb_PName.Text)
        cmd.Parameters.AddWithValue("@f2", Format(Now(), "dd/MM/yyyy ") & Format(Now(), "HH:mm:ss")) 'meaning: add the time when the picture is uploaded'
        cmd.Parameters.AddWithValue("@f3", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f4", ddl_Category.SelectedValue)
        cmd.Parameters.AddWithValue("@f5", tb_Location.Text)
        cmd.Parameters.AddWithValue("@f6", "Pictures/" & newFileName)
        cmd.ExecuteNonQuery()
        oleDbConn.Close()

        Response.Redirect("Photolist.aspx")

    End Sub
End Class